home *** CD-ROM | disk | FTP | other *** search
/ Aminet 21 / Aminet 21 (1997)(GTI - Schatztruhe)[!][Oct 1997].iso / Aminet / gfx / show / gs_src_gs.lha / gs5.03 / gxbcache.h < prev    next >
C/C++ Source or Header  |  1996-06-11  |  4KB  |  117 lines

  1. /* Copyright (C) 1995, 1996 Aladdin Enterprises.  All rights reserved.
  2.   
  3.   This file is part of Aladdin Ghostscript.
  4.   
  5.   Aladdin Ghostscript is distributed with NO WARRANTY OF ANY KIND.  No author
  6.   or distributor accepts any responsibility for the consequences of using it,
  7.   or for whether it serves any particular purpose or works at all, unless he
  8.   or she says so in writing.  Refer to the Aladdin Ghostscript Free Public
  9.   License (the "License") for full details.
  10.   
  11.   Every copy of Aladdin Ghostscript must include a copy of the License,
  12.   normally in a plain ASCII text file named PUBLIC.  The License grants you
  13.   the right to copy, modify and redistribute Aladdin Ghostscript, but only
  14.   under certain conditions described in the License.  Among other things, the
  15.   License requires that the copyright notice and this notice be preserved on
  16.   all copies.
  17. */
  18.  
  19. /* gxbcache.h */
  20. /* Bitmap cache structures */
  21. #include "gxbitmap.h"
  22.  
  23. /*
  24.  * These structures are superclasses for a cache in which the 'value' is
  25.  * a bitmap.  The structures defined here don't take any position about
  26.  * the nature of the 'key'.
  27.  */
  28.  
  29. /* ---------------- Bitmap cache entry ---------------- */
  30.  
  31. /*
  32.  * The cache may contain both used and free blocks.
  33.  * All blocks have a common header; free blocks have ONLY the header.
  34.  */
  35. typedef struct gx_cached_bits_head_s {
  36.     uint size;            /* total block size in bytes */
  37.     uint depth;            /* bits per pixel, free block if 0 */
  38. } gx_cached_bits_head;
  39. #define cb_head_is_free(cbh) ((cbh)->depth == 0)
  40. #define cb_head_set_free(cbh) ((cbh)->depth = 0)
  41. #define gx_cached_bits_common\
  42.     gx_cached_bits_head head;    /* must be first */\
  43.         /* The rest of the entry is an abbreviation of */\
  44.         /* gx_strip_bitmap, sans data. */\
  45.     ushort width, height, shift;\
  46.     ushort raster;\
  47.     gx_bitmap_id id
  48. /* Define aliases for head members. */
  49. #define cb_depth head.depth
  50. /* Define aliases for common members formerly in the head. */
  51. #define cb_raster raster
  52. typedef struct gx_cached_bits_s {
  53.     gx_cached_bits_common;
  54. } gx_cached_bits;
  55. #define cb_is_free(cb) cb_head_is_free(&(cb)->head)
  56. /*
  57.  * Define the alignment of the gx_cached_bits structure.  We must ensure
  58.  * that an immediately following bitmap will be properly aligned.
  59.  */
  60. #define align_cached_bits_mod\
  61.   (max(align_bitmap_mod, max(arch_align_ptr_mod, arch_align_long_mod)))
  62.  
  63. /*
  64.  * We may allocate a bitmap cache in chunks, so as not to tie up memory
  65.  * prematurely if it isn't needed (or something else needs it more).
  66.  * Thus there is a structure for managing an entire cache, and another
  67.  * structure for managing each chunk.
  68.  */
  69. typedef struct gx_bits_cache_chunk_s gx_bits_cache_chunk;
  70. struct gx_bits_cache_chunk_s {
  71.     gx_bits_cache_chunk *next;
  72.     byte *data;        /* gx_cached_bits_head * */
  73.     uint size;
  74.     uint allocated;        /* amount of allocated data */
  75. };
  76.  
  77. /* ---------------- Bitmap cache ---------------- */
  78.  
  79. #define gx_bits_cache_common\
  80.     gx_bits_cache_chunk *chunks;    /* current chunk in circular list */\
  81.     uint cnext;            /* rover for allocating entries */\
  82.                     /* in current chunk */\
  83.     uint bsize;            /* total # of bytes for all entries */\
  84.     uint csize            /* # of entries */
  85. typedef struct gx_bits_cache_s {
  86.     gx_bits_cache_common;
  87. } gx_bits_cache;
  88.  
  89. /* ---------------- Procedural interface ---------------- */
  90.  
  91. /* ------ Entire cache ------ */
  92.  
  93. /* Initialize a cache.  The caller must allocate and initialize */
  94. /* the first chunk. */
  95. void gx_bits_cache_init(P2(gx_bits_cache *, gx_bits_cache_chunk *));
  96.  
  97. /* ------ Chunks ------ */
  98.  
  99. /* Initialize a chunk.  The caller must allocate it and its data. */
  100. void gx_bits_cache_chunk_init(P3(gx_bits_cache_chunk *, byte *, uint));
  101.  
  102. /* ------ Individual entries ------ */
  103.  
  104. /* Attempt to allocate an entry.  If successful, set *pcbh and return 0. */
  105. /* If there isn't enough room, set *pcbh to an entry requiring freeing, */
  106. /* or to 0 if we are at the end of the chunk, and return -1. */
  107. int gx_bits_cache_alloc(P3(gx_bits_cache *, ulong, gx_cached_bits_head **));
  108.  
  109. /* Shorten an entry by a given amount. */
  110. void gx_bits_cache_shorten(P4(gx_bits_cache *, gx_cached_bits_head *,
  111.                   uint, gx_bits_cache_chunk *));
  112.  
  113. /* Free an entry.  The caller is responsible for removing the entry */
  114. /* from any other structures (like a hash table). */
  115. void gx_bits_cache_free(P3(gx_bits_cache *, gx_cached_bits_head *,
  116.                gx_bits_cache_chunk *));
  117.